import type { EamEquipmentType } from "@/pages/eam/equipmentType/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
	//设备类型
	name?: string;
	//类别
	category?: string;
	//当前页码
	page: number;
	//每页数量
	pageSize: number;
}

export interface PageListRes {
	//总记录数
	total: number;
	//数据列表
	records: EamEquipmentType[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
	apiClient.post({
		url: "/eam/equipment/type/pageList",
		data,
	});
const getInfo = (id: React.Key): Promise<EamEquipmentType> =>
	apiClient.get({
		url: `/eam/equipment/type/${id}`,
	});

const add = (data: EamEquipmentType): Promise<EamEquipmentType> =>
	apiClient.post({
		url: "/eam/equipment/type",
		data,
	});

const update = (data: EamEquipmentType): Promise<EamEquipmentType> =>
	apiClient.put({
		url: "/eam/equipment/type",
		data,
	});

const remove = (ids: React.Key[]): Promise<void> =>
	apiClient.delete({
		url: "/eam/equipment/type",
		params: {
			ids: ids.join(","),
		},
	});

// 获取下拉列表
const getTypeSelectList = (): Promise<EamEquipmentType[]> =>
	apiClient.get({
		url: "/eam/equipment/type/selectList",
	});

export const eamEquipmentTypeService = {
	pageList,
	getTypeSelectList,
	getInfo,
	add,
	update,
	remove,
};

export default eamEquipmentTypeService;
